package com.ht.dao;

import com.ht.bean.Dep;
import com.ht.bean.Emp;
import com.ht.bean.Feedback;
import com.ht.bean.Post;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface FeedbackDao {
    //-------------------------------------------------------------------------------
    //问题反馈模块
    //查询查阅
    @Select("select fk.feedBackType,fk.empId,fk.empname,fk.feedbackTime,fk.remark,fk.image,fk.opinion,fk.userId  from feedback fk where feedbackId= #{feedbackId}")
    Map allcheck(Integer feedbackId);

    //查询部门表
    @Select("select * from dep")
    List<Dep> alldep(Integer depid, String depName);

    //查询feedback表
    @Select({"<script>",
            "select fk.feedbackId,fk.feedBackType,fk.empId,fk.empName,fk.feedbackTime,fk.remark,fk.image,fk.status,d.depName,fk.opinion,fk.userId,fk.replyTime from feedback fk,dep d where fk.depId=d.depid",
            "<if test=\"fk.feedbackId!=null and fk.feedbackId!=''\">",
            "and fk.feedbackId=#{fk.feedbackId}",

            "</if>",
            "<if test=\"fk.empName!=null and fk.empName!=''\">",
            " and fk.empName like concat('%',#{fk.empName},'%')",

            "</if>",

            "order by fk.status+0 ,fk.feedbackTime  asc limit #{startIndex},#{pageSize}",
            "</script>"})
    public List<Map> alllist(@Param("startIndex") Integer  startIndex, @Param("pageSize") Integer pageSize, @Param("fk") Feedback fk);
    //查询总行数
    @Select({"<script>",
            "select count(*) from feedback fk,dep d where fk.depId=d.depid",

            "<if test=\"fk.feedbackId!=null and fk.feedbackId!=''\">",
            "and fk.feedbackId=#{fk.feedbackId}",

            "</if>",
            "<if test=\"fk.empName!=null and fk.empName!=''\">",
            " and fk.empName like concat('%',#{fk.empName},'%')",

            "</if>",
            "</script>"})
    public int countfk(@Param("fk") Feedback fk);

    //新增
    @Insert("insert into feedback values(null,#{feedBackType},#{empId},#{empName},#{feedbackTime},#{remark},#{image},#{status},#{depId},#{opinion},#{userId},#{replyTime})")
    boolean addfk(Feedback feedback);

    //查询职务表
    @Select("select * from post")
    List<Post> allpost();

    //审批

    @Update("update feedback set status=#{status},opinion=#{opinion},userId=#{userId} where feedbackId=#{feedbackId}")
    boolean sp(Feedback feedback);

    //查询ID
    @Select("select * from feedback  where feedbackId=#{feedbackId} ")
    List<Feedback> fkid(@Param("feedbackId") Integer feedbackId);


}
